package eu.dominicum.ft.pd.mao.validator;

import eu.dominicum.ft.pd.mao.MakeParticipantMAO;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * Custom validator to validate between the properties person and personID.
 *
 * @author Harry Klerks
 * @since 2013M1
 */
public class NewOrExistingPersonValidator
        implements ConstraintValidator<NewOrExistingPerson,
        MakeParticipantMAO> {

    @Override
    public void initialize(final NewOrExistingPerson newOrExistingPerson) {

    }

    @Override
    public final boolean isValid(final MakeParticipantMAO makeParticipantMAO,
                                 final ConstraintValidatorContext constraintValidatorContext) {

        Long personId = makeParticipantMAO.getPersonId();
        String personName = makeParticipantMAO.getMakePersonMAO().getName();

        return personName != null || personId != 0;
    }
}
